﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

namespace SqirmySeq
{
    class Globe
    {
        public static string Pattern { get { return "A+(CAT|TAC)A"; } }
    }

    class Leg
    {
        public static string Pattern { get { return "CG+T"; } }
    }

    class Eyespot
    {
        private static string NonStalk { get { return "TAG"; } }
        private static string HasStalk { get { return string.Format("T({0})+AG", Leg.Pattern); } }
        public static string Pattern { get { return string.Format("{0}|{1}", NonStalk, HasStalk); } }
    }

    class Head
    {
        public static string Pattern { get { return string.Format("{0}({1})+", Globe.Pattern, Eyespot.Pattern); } }
    }

    class Body
    {
        public static string Pattern { get { return string.Format("{0}({1})+", Globe.Pattern, Leg.Pattern); } }
    }

    class Squirmy
    {
        public static string Pattern { get { return string.Format("^{0}({1})+$", Head.Pattern, Body.Pattern); } }
    }

    class Program
    {
        //static void Main(string[] args)
        //{
            //if (File.Exists(@"C:\eerie.in"))
            //{
            //    using (StreamReader sr = new StreamReader(new FileStream(@"C:\eerie.in", FileMode.Open)))
            //    using (StreamWriter sw = new StreamWriter(new FileStream(@"C:\eerie.out", FileMode.OpenOrCreate | FileMode.Truncate)))
            //    {
            //        sw.WriteLine("SQUIRMY OUTPUT");

            //        int caseCnt = TryParsetLine(sr.ReadLine());

            //        for (int i = 0; i < caseCnt; i++)
            //        {
            //            string line = sr.ReadLine();

            //            sw.WriteLine(string.Format("Case {0}: {1}", i + 1, new Regex(Squirmy.Pattern).IsMatch(line) ? "YES" : "NO"));
            //        }

            //        sw.WriteLine("END OF OUTPUT");

            //    }
            //}
        //}

        private static int TryParsetLine(string line)
        {
            int i = 0;
            if (int.TryParse(line, out i) && i >= 0)
            {
                //totalLines = i;
            }
            return i;
        }
    }
}
